package com.xhwl.data.controller;

import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xhwl.common.pojo.ResultJson;
import com.xhwl.common.pojo.cent.sdata.EnterpriseAppConfig;
import com.xhwl.data.service.IEnterpriseAppConfigService;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 移动端产品配置-运管平台配置使用
 *
 * @Author: lrp
 * @Description: 移动端产品配置
 * @Date: Create in 10:05 2022/05/30
 * @menu 移动端产品配置
 */
@RestController
public class EnterpriseAppConfigController {

    @Autowired
    private IEnterpriseAppConfigService enterpriseAppConfigService;

    /**
     * 列表查询
     * @param industryId
     * @param page
     * @return
     */
    @GetMapping("/enterprise-app-config/page")
    public ResultJson page(@RequestParam(value = "industryId", required = true) Short industryId, Page page) {
        page.setRecords(OrderItem.descs("created_at"));
        Page<EnterpriseAppConfig> page1 = enterpriseAppConfigService.page(industryId, page);
        return ResultJson.success(page1);
    }


    /**
     * 批量新增（暂不使用）
     * @param enterpriseAppConfigs
     * @return
     */
    @PostMapping("/enterprise-app-config/batch-create")
    public ResultJson batchCreate(@RequestBody List<EnterpriseAppConfig> enterpriseAppConfigs) {
        if (CollectionUtils.isEmpty(enterpriseAppConfigs) || enterpriseAppConfigs.size() > 5) {
            ResultJson.fail("参数错误，移动端产品配置在1~5个范围内");
        }
        return enterpriseAppConfigService.batchCreate(enterpriseAppConfigs);
    }


    /**
     * 批量添加/修改
     * @param enterpriseAppConfigs
     * @return
     */
    @PostMapping("/enterprise-app-config/batch-update")
    public ResultJson update(@RequestBody List<EnterpriseAppConfig> enterpriseAppConfigs) {
        if (CollectionUtils.isEmpty(enterpriseAppConfigs) || enterpriseAppConfigs.size() > 5) {
            ResultJson.fail("参数错误，移动端产品配置在1~5个范围内");
        }
        return enterpriseAppConfigService.batchUpdate(enterpriseAppConfigs);
    }

}
